/*
This file is part of SmartShopper

SmartShopper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

SmartShopper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with vlc-remote.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.1
import com.meego 1.0

Rectangle {
    id: pageHeader
    property alias title: textTitle.text
    property string iconDown: ""
    property string iconUp: ""
    property real oldOpacity: 1.0
    property int sortOrder : 0
    property bool sortDown : true
    property variant dialogModel: 0
    property string dialogCaption: ""
    anchors.top: parent.top
    width: parent.width
    height: 56
//    z: 12

    signal iconClicked()
    signal dialogAccpeted(int idx)

    Column {
        spacing: 0
        Row {
            Item {
                width: 12
                height: pageHeader.height
            }
            Text {
                id: textTitle
                width: pageHeader.width / 2
                height: pageHeader.height
                font.pixelSize: 38
                font.letterSpacing: -3
                font.bold: false
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignLeft
                color: theme.inverted ? "white" : "black"
            }
            Item{
                width:8
                height: pageHeader.height
            }
            Text {
                id: sortBy
                width: pageHeader.width / 2 - 44 * 2
                height: pageHeader.height
                font.pixelSize: 30
                font.letterSpacing: -3
                font.bold: false
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignRight
                color: theme.inverted ? "white" : "black"
                text: dialogModel.get(sortOrder).name
                MouseArea {
                    anchors.fill: parent
                    onClicked: selectionDialog.open()
                }
            }
            ToolIcon {
                id: iconType
                property bool sorted: true
                platformIconId: sortDown ? iconDown : iconUp

                MouseArea {
                    anchors.fill: parent
                    onClicked: pageHeader.iconClicked() //listControl.sortDown = !listControl.sortDown
                }
            }
        }
    }

    SelectionDialog {
        id: selectionDialog
        model: dialogModel
        titleText: dialogCaption
        selectedIndex: sortOrder
        onAccepted: pageHeader.dialogAccpeted(selectedIndex) //listControl.sortOrder = selectedIndex
    }

}
